import Vue from 'vue';
import Router from 'vue-router';
import show from "../view/components/show.vue";
import Login from "../view/components/login.vue";
import Register from "../view/components/register.vue";
import xq from "../view/components/xq.vue";
import OrderSubmit from "../view/components/order/OrderSubmit.vue";
import EditAddress from "../view/components/address/EditAddress.vue";
import AddressAll from "../view/components/address/AddressAll.vue";
import MyShow from "../view/components/my/MyShow.vue";
import Seting from "../view/components/my/Seting.vue";
import ZhangHao from "../view/components/my/ZhangHao.vue";
import SetPayPassword from "../view/components/my/SetPayPassword.vue";
import Help from "../view/components/wpl/help.vue";
import Feedback from "../view/components/wpl/feedback.vue";
import Me from "../view/components/wpl/me.vue";
import PersonalCenter from "../view/components/PersonalCenter.vue";
import OrderPage from "../view/components/order/OrderPage.vue";
import PersonalProfile from "../view/components/PersonalProfile.vue";
import edit from "../view/components/edit.vue";
import PaySuccess from "../view/components/PaySuccess.vue";
import OrderSubmit02 from "../view/components/order/orderSubmit02.vue";
import SouSuo from "../view/components/show/SouSuo.vue";
import PayError from "../view/components/PayError.vue";
import OrderShow from "../view/components/order/OrderShow.vue";
import MyScore from "../view/components/my/MyScore.vue";
import YinSi from "../view/components/my/YinSi.vue";
import FuWu from "../view/components/my/FuWu.vue";
import Login02 from "../view/components/login02.vue";
import UpdatePassword from "../view/components/updatepassword.vue";
Vue.use(Router);

const routes = [
  //积分商城页面
  {
    path: '/show',
    name: 'show',
    component: show,
    meta: { requiresAuth: false } // 需要登录才能访问
  },
  //登录页面
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  {
    path: '/',
    name: 'Login02',
    component: Login02,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //注册页面
  {
    path: '/register',
    name:'register',
    component: Register,
  },
  {
    path: '/updatepassword',
    name: 'UpdatePassword',
    component: UpdatePassword,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //搜索页面
  {
    path: '/souSuo',
    name:'SouSuo',
    component: SouSuo,
  },
  //订单详情页面
  {
    path: '/xq',
    name: 'xq',
    component: xq,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //订单提交页面
  {
    path: '/orderSubmit',
    name: 'OrderSubmit',
    component: OrderSubmit,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //未支付跳转的订单支付页面
  {
    path: '/orderSubmit02',
    name: 'OrderSubmit02',
    component: OrderSubmit02,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  {
    path: '/orderPage',
    name: 'OrderPage',
    component: OrderPage,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  // 所以地址
  {
    path: '/addressAll',
    name: 'AddressAll',
    component: AddressAll,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //编辑地址页面
  {
    path: '/editAddress',
    name: 'editAddress',
    component: EditAddress,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  // 个人中心首页
  {
    path: '/myShow',
    name: 'MyShow',
    component: MyShow,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //我的积分页面
  {
    path: '/myScore',
    name: 'MyScore',
    component: MyScore,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //设置页面
  {
    path: '/seting',
    name: 'Seting',
    component: Seting,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //账号安全页面
  {
    path: '/zhangHao',
    name: 'ZhangHao',
    component: ZhangHao,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //隐私协议页面
  {
    path: '/yinSi',
    name: 'YinSi',
    component: YinSi,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //用户服务协议页面
  {
    path: '/fuWu',
    name: 'FuWu',
    component: FuWu,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //设置支付密码页面
  {
    path: '/setPayPassword',
    name: 'SetPayPassword',
    component: SetPayPassword,
    meta: { requiresAuth: false } // 不需要登录即可访问
  },
  {
    path: '/help',
    name:'help',
    component: Help,
  },
  {
    path: '/feedback',
    name:'feedback',
    component: Feedback,
  },
  {
    path: '/me',
    name:'me',
    component: Me,
  },
  {
    path: '/PersonalCenter',
    name: 'PersonalCenter',
    component: PersonalCenter,
    //meta: { requiresAuth: false } // 需要登录才能访问
  },
  //订单列表
  {
    path: '/OrderPage',
    name: 'OrderPage',
    component: OrderPage,
    //meta: { requiresAuth: false } // 需要登录才能访问
  },
  //订单列表
  {
    path: '/orderShow',
    name: 'OrderShow',
    component: OrderShow,
    //meta: { requiresAuth: false } // 需要登录才能访问
  },

  {
    path: '/PersonalProfile',
    name: 'PersonalProfile',
    component: PersonalProfile,
    // meta: { requiresAuth: false } // 不需要登录即可访问
  },
  {
    path: '/edit',
    name: 'edit',
    component: edit,
    // meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //支付成功页面
  {
    path: '/paySuccess',
    name: 'PaySuccess',
    component: PaySuccess,
    // meta: { requiresAuth: false } // 不需要登录即可访问
  },
  //支付失败页面
  {
    path: '/payError',
    name: 'PayError',
    component: PayError,
    // meta: { requiresAuth: false } // 不需要登录即可访问
  },


];

const router = new Router({
  routes
});

// 全局路由守卫，用于判断登录状态并决定是否允许访问页面
router.beforeEach((to, from, next) => {
  const loginInfo = localStorage.getItem('loginInfo'); // 模拟从本地存储获取登录状态，实际可替换为与后端验证的逻辑
  if (to.meta.requiresAuth &&!loginInfo) {
    next('/login'); // 如果需要登录但未登录，跳转到登录页面
  } else {
    next();
  }
});

export default router;
